package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserAccountMapper;
import com.qf.mapper.DtsUserMapper;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.vo.DayStatis;
import org.apache.ibatis.ognl.security.UserMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private DtsUserMapper dtsUserMapper;

    @Autowired
    private DtsUserAccountMapper dtsUserAccountMapper;

    @Override
    public int countUser() {
        QueryWrapper<DtsUser> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("deleted",false);

        Integer count = dtsUserMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public List<DayStatis> incroCount() {

        List<DayStatis> list = dtsUserMapper.staticIncreaseUser();
        return list;
    }

    @Override
    public IPage<DtsUser> queryUserPage(String name, String mobile, Integer page, Integer limit, String sort, String order) {

        IPage<DtsUser> ipage = new Page<>(page,limit);

        QueryWrapper<DtsUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted",false);

        if (!StringUtils.isEmpty(mobile)) {
            queryWrapper.eq("mobile", mobile);
        }
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like("username",name);
        }


        IPage<DtsUser> resultPage  = dtsUserMapper.selectPage(ipage, queryWrapper);

        return resultPage ;
    }

    @Override
    public DtsUserAccount selectUserAccountById(Integer userId) {
        QueryWrapper<DtsUserAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",userId);
        DtsUserAccount userAccount = dtsUserAccountMapper.selectById(userId);
        return userAccount;
    }


}
